package com.platform.web.controller.system;

import java.util.List;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.platform.common.annotation.Log;
import com.platform.common.core.controller.BaseController;
import com.platform.common.core.domain.AjaxResult;
import com.platform.common.enums.BusinessType;
import com.platform.system.domain.ProAddress;
import com.platform.system.service.IProAddressService;
import com.platform.common.utils.poi.ExcelUtil;
import com.platform.common.core.page.TableDataInfo;

/**
 * 地址Controller
 *
 * @author platform
 * @date 2025-02-23
 */
@Tag(name = "地址", description = "")
@RestController
@RequestMapping("/system/address")
public class ProAddressController extends BaseController {
    @Autowired
    private IProAddressService proAddressService;

    /**
     * 查询地址列表
     */
    @Operation(summary = "查询地址列表")
    @GetMapping("/listAll")
    public AjaxResult listAll() {
        ProAddress proAddress = new ProAddress();
        proAddress.setUserId(getUserId());
        List<ProAddress> list = proAddressService.selectProAddressListAll(proAddress);
        return success(list);
    }

    /**
     * 查询地址列表
     */
    @Operation(summary = "查询地址列表")
    @PreAuthorize("@ss.hasPermi('system:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProAddress proAddress) {
        startPage();
        List<ProAddress> list = proAddressService.selectProAddressList(proAddress);
        return getDataTable(list);
    }

    /**
     * 导出地址列表
     */
    @Operation(summary = "导出地址列表")
    @PreAuthorize("@ss.hasPermi('system:address:export')")
    @Log(title = "地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProAddress proAddress) {
        List<ProAddress> list = proAddressService.selectProAddressList(proAddress);
        ExcelUtil<ProAddress> util = new ExcelUtil<ProAddress>(ProAddress.class);
        util.exportExcel(response, list, "地址数据");
    }

    /**
     * 获取地址详细信息
     */
    @Operation(summary = "获取地址详细信息")
    @PreAuthorize("@ss.hasPermi('system:address:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(proAddressService.selectProAddressById(id));
    }

    /**
     * 新增地址
     */
    @Operation(summary = "新增地址")
//    @PreAuthorize("@ss.hasPermi('system:address:add')")
    @Log(title = "地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProAddress proAddress) {
        proAddress.setUserId(getUserId());
        proAddress.setCreateBy(getUsername());
        return toAjax(proAddressService.insertProAddress(proAddress));
    }

    /**
     * 修改地址
     */
    @Operation(summary = "修改地址")
//    @PreAuthorize("@ss.hasPermi('system:address:edit')")
    @Log(title = "地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProAddress proAddress) {
        proAddress.setUpdateBy(getUsername());
        return toAjax(proAddressService.updateProAddress(proAddress));
    }

    /**
     * 删除地址
     */
    @Operation(summary = "删除地址")
//    @PreAuthorize("@ss.hasPermi('system:address:remove')")
    @Log(title = "地址", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(proAddressService.deleteProAddressByIds(ids));
    }
}
